package com.ctbri.JWLetter.controller;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.ctbri.JWLetter.frame.JWJSONObject;
import com.ctbri.JWLetter.frame.RequestTemplate;
import com.ctbri.JWLetter.frame.ResponseTemplate;
import com.ctbri.JWLetter.service.RelationGraphService;

/**
 * 关系图谱控制层实现
 * 
 * @author Hogan
 *
 */
@Controller
@RequestMapping("/graph")
public class RelationGraphController {

	private Logger log = Logger.getLogger(getClass());

	@Resource
	private RelationGraphService graphService;

	/**
	 * 加载关系图谱
	 * 
	 * @param jo
	 * @return
	 */
	@RequestMapping("loadGraph")
	public @ResponseBody JSONObject loadGraph(@RequestBody JSONObject jo) {
		JWJSONObject detail = null;
		try {
			RequestTemplate rt = new RequestTemplate(jo);
			detail = graphService.loadGraph(rt.getJParams());
		} catch (Exception e) {
			log.error("加载关系图谱失败!", e);
			return new ResponseTemplate().getReturn();
		}
		return new ResponseTemplate(detail).getReturn();
	}
	
	/**
	 * 加载关系下信件信息
	 * 
	 * @param jo
	 * @return
	 */
	@RequestMapping("loadRelationLetters")
	public @ResponseBody JSONObject loadRelationLetters(@RequestBody JSONObject jo) {
		JWJSONObject detail = null;
		try {
			RequestTemplate rt = new RequestTemplate(jo);
			detail = graphService.loadRelationLetters(rt.getJParams());
		} catch (Exception e) {
			log.error("加载关系下信件信息失败!", e);
			return new ResponseTemplate().getReturn();
		}
		return new ResponseTemplate(detail).getReturn();
	}
	
}
